package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuDataService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/menu")
public class MenuDataController {
    @Reference
    private MenuDataService menuDataService;
    @PostMapping ("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("[菜单-查询]data:{}",queryPageBean);
        PageResult pageResult=menuDataService.pageQuery(queryPageBean);
        return new Result(true, MessageConst.GET_MENU_SUCCESS,pageResult);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Menu menu,Integer menuDataId){
        log.info("[菜单-新增]data:{},menuDataId",menu,menuDataId);
        menuDataService.add(menu,menuDataId);
        return new Result(true,MessageConst.ACTION_SUCCESS);
    }

    @GetMapping("/findById")
    public Result findById(Integer id){
        log.info("[菜单-根据id查询]id:{}",id);
        Menu menu= menuDataService.selectById(id);
        return new Result(true,"根据ID查询成功",menu);
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody Menu menu){
        log.info("[菜单-编辑]data:{},menuDataId:{}",menu);
        menuDataService.edit(menu);
        return new Result(true,"恭喜您编辑成功!");
    }
    @RequestMapping("/delete")
    public Result delete(Integer id){
        log.info("[菜单-删除]data:{}",id);
        menuDataService.delete(id);
        return new Result(true,"删啦删啦!");
    }
}
